home *** CD-ROM | disk | FTP | other *** search
- { SPX Library Version 3.0 Copyright 1993 Scott D. Ramsay }
-
- SPX_VGA is the main graphics kernel. All the graphic primitives
- are here.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure VSinc;
-
- Waits for a vertical retrace to occur.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure setclip(x1,y1,x2,y2:integer);
-
- Sets the clipping region.
-
- (WinMinX,WinMinY) - (WinMaxX,WinMaxY)
- ───────────────────────────────────────────────────────────────────────────
- procedure resetclip;
-
- Resets the clipping region to the size of the screen.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure translatebox(x1,y1,x2,y2:integer;var table);
-
- Draws a box using a translation table.
-
- X1,Y1: Top-left coordinate of the region;
- X2,Y2: Bottom-right coordinate of the region;
- table: Must be of size 256 bytes: { array[0..255] of byte }
-
- The pixels color within the box becomes an index to the table. The
- value in the table becomes the color displayed.
-
- e.g.
-
- var
- i : integer;
- table : array[0..255] of byte;
- begin
- for i := 0 to 255 do
- table[i] := i;
- table[40] := 2;
-
- translatebox(100,100,110,110,table);
- end;
-
- The above example will change only the color 40 in the region to
- color 2.
- ───────────────────────────────────────────────────────────────────────────
- procedure LightColor(var color:RGBtype;percent:byte);
-
- Brightens the palette type by a percentage.
-
- LightColor(color,100); { changes the color to pure white }
- LightColor(color,50); { changes the color to 50% brighter }
-
- ───────────────────────────────────────────────────────────────────────────
- procedure DarkColor(var color:RGBtype;percent:byte);
-
- Darkens the palette type by a percentage.
-
- LightColor(color,100); { changes the color to pure black }
- LightColor(color,50); { changes the color to 50% darker }
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CreateDarkTable(var colors;var dktable;percent:integer);
-
- Creates a Darkening Table. Does not change the palette just a translation
- table.
-
- colors : RGBlist type to darken
- dktable : array[0..255] of byte; will contain the darkening table
- perenct : percentage to darken
-
- Creates a translation table with the passed in palette tries to find
- a corresponding dark color.
-
- Use with translatebox, fxtput_clip
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CreateLightTable(var colors;var ltable;percent:integer);
-
- Creates a light table. Does not change the palette just a translation
- table.
-
- colors : RGBlist type to brighten. (Does not change the palette)
- ltable : array[0..255] of byte; will contain the light table
- perenct : percentage to brighten
-
- Creates a translation table with the passed in palette tries to find
- a corresponding light color.
-
- Use with translatebox, fxtput_clip
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetDefaultColors;
-
- Sets the VGA palette to the default SPX library colors.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Switch(var a,b:integer);
-
- Exchanges the values of A and B.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Parse(var x,y:integer);
-
- Clips the point (x,y). to the legal range.
-
- X: Column coordinate 0..319;
- Y: Row coordinate 0..199
-
- ───────────────────────────────────────────────────────────────────────────
- function BuffSize(x,y:integer):word;
-
- Returns the size of the buffer needed for a sprite size of (x,y).
-
- X: Width of the sprite;
- Y: Height of the sprite
-
- ───────────────────────────────────────────────────────────────────────────
- function ImageSize(var image):word;
-
- Returns the size of the memory used by the sprite.
-
- IMAGE: Sprite
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ImageDims(var image;var x,y:integer);
-
- Returns the width and height of a sprite.
-
- IMAGE: Sprite;
- X: Width of the sprite;
- Y: Height of the sprite
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetPtr(var i:PtrRec;var buff);
-
- Returns a PtrRec (Segment:offset) of a given buffer.
-
- I: Returning record;
- BUFF: Any memory buffer or variable
-
- ───────────────────────────────────────────────────────────────────────────
- function pt(x,y:integer):word;
-
- Returns the offset of the location (x,y).
-
- X: Column position;
- Y: Row position
-
- ───────────────────────────────────────────────────────────────────────────
- procedure OpenMode(npages:byte);
-
- Sets the VGA to 320x200x256 mode and allocates virtual pages.
-
- NPAGES: Number of pages to use
-
- NOTE: Page 1 is always the visual page. Pages 2..n are created
- dynamically on the heap.
-
- ───────────────────────────────────────────────────────────────────────────
- function Point(x,y:integer;pg:byte):byte;
-
- Returns the color value of a location on a page.
-
- X: Column position;
- Y: Row position;
- PG: Page to retrieve the color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Pset(x,y:integer;n:byte);
-
- Draw a point onto the active page.
-
- X: Column position;
- Y: Row position;
- n: Color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fPcopy(var from,too);
-
- Copies one page to another.
-
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- NOTE: If 386 or later processor is present, 386 copies will be used.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Pcopy(from,too:byte);
-
- Same as fPcopy, copies only predefined virtual pages.
-
- FROM: Page number of the source page;
- TOO: Page number of the destination page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CopyRect(x1,y1,x2,y2:integer;var from,too);
-
- Copy a rectangular region from one page to another.
-
- X1,Y1: Top-left coordinate of the region;
- X2,Y2: Bottom-right coordinate of the region;
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- EXAMPLE:
-
- CopyRect(100,100,200,140,pages[2]^,pages[1]^);
-
- Copies a region on page 2 to the visual page.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fwCopyRect(x1,y1,x2,y2:integer;var from,too);
-
- Same as CopyRect. Forces even amount width moves.
-
- X1,Y1: Top-left coordinate of the region;
- X2,Y2: Bottom-right coordinate of the region;
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- NOTE: Make sure that (X2-X1+1) is an even number. Unpredictable results
- will happen if the source and destination page are the same.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SwapRect(x1,y1,x2,y2:integer;from,too:byte);
-
- Exchange regions from two pages.
-
- X1,Y1: Top-left coordinate of the region;
- X2,Y2: Bottom-right coordinate of the region;
- FROM: Page number of the source page;
- TOO: Page number of the destination page
-
- NOTE: Unpredictable results will happen if the source and destination
- page are the same.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Line_clip(x1,y1,x2,y2:integer;n:byte);
-
- Draws a line on the active page. Clips the line according to
- WinMinX, WinMinY, WinMaxX, WinMaxY.
-
- X1,Y1: Coordinate one of the line;
- X2,Y2: Coordinate two of the line;
- n: Color of line
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Line(x1,y1,x2,y2:integer;n:byte);
-
- Draw a line on the active page. DOES NOT preform any clipping. Faster
- than the Line_clip procedure.
-
- X1,Y1: Coordinate one of the line;
- X2,Y2: Coordinate two of the line;
- n: Color of line
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Bar(x1,y1,x2,y2:integer;n:byte);
-
- Draws a filled rectangle on the active page.
-
- X1,Y1: Coordinate one of the bar;
- X2,Y2: Coordinate two of the bar;
- n: Color of bar
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Rectangle(x1,y1,x2,y2:integer;n:byte);
-
- Draws a rectangle on the active page.
-
- X1,Y1: Coordinate one of the rectangle;
- X2,Y2: Coordinate two of the rectangle;
- n: Color of bar
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Circle(x1,y1,r:integer;n:byte);
-
- Draws a circle on the active page.
-
- X1,Y1: Center coordinate of the circle;
- R: Radius of the circle;
- N: Color of circle
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Ellipse(xc,yc,a0,b0:integer;c:byte);
-
- Draws an ellipse on the active page.
-
- XC,YC: Center coordinate of the ellipse;
- A0: Height radius of ellipse;
- B0: Width radius of ellipse;
- C: Color of ellipse
-
- ───────────────────────────────────────────────────────────────────────────
- procedure cls(b:byte);
-
- Clears the active page.
-
- B: The color to clear the active page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CloseMode;
-
- Restores the video mode and deallocates virtual pages.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetPageActive(page:byte);
-
- Changes the active page.
-
- PAGE: New page number to become active.
-
- NOTE: If allocated memory for virtual page. Use SCNSEG:SCNOFS to
- change the active page.
-
- EXAMPLE:
- var
- MyVirt : pointer;
- .
- .
- .
-
- Getmem(MyVirt,64000); { Allocate a virtual page }
- SetPageActive(1); { Sets the active page to page 1 }
-
- SCNSEG := seg(MyVirt^); { Sets the active page to MyVirt }
- SCNOFS := ofs(MyVirt^);
-
- ───────────────────────────────────────────────────────────────────────────
- procedure GetColor(num:byte;var red,green,blue:byte);
-
- Retrieves a color from the current palette.
-
- NUM: Color number;
- RED: Red componet of the color;
- GREEN: Green componet of the color;
- BLUE: Blue componet of the color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetColor(num,red,green,blue:byte);
-
- Sets a color of the current palette.
-
- NUM: Color number;
- RED: Red componet of the color;
- GREEN: Green componet of the color;
- BLUE: Blue componet of the color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fSetColors(var colors);
-
- Sets all the colors of the current palette.
-
- COLORS: A buffer which contains a red, green and blue componet for
- each of the 256 colors
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fGetColors(var colors);
-
- Retrieves all the colors from the current palette.
-
- COLORS: A buffer which will contain a red, green and blue componet for
- each of the 256 colors
-
- NOTE: Can be used repeatedly for custom fades. (Does not flicker)
-
- ───────────────────────────────────────────────────────────────────────────
- procedure FadeIn(steps:word;var color);
-
- Fade the screen from black to the palette specified.
-
- STEPS: Speed of the fade;
- COLOR: Final palette after the fade
-
- ───────────────────────────────────────────────────────────────────────────
- procedure FadeOut(steps:word;var color);
-
- Fade the screen from palette specified to black.
-
- STEPS: Speed of the fade;
- COLOR: Palette before the fade, (Usually is the current palette)
-
- EXAMPLE:
-
- var
- Apal : RGBlist;
-
- fgetcolors(Apal); { grab the current palette }
- FadeOut(30,Apal); { Fade the screen to black }
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ColorsChange(var color:rgblist;filter:rgbtype);
-
- Change the color palette using a color filter.
-
- COLOR: Palette to change;
- FILTER: Red, green, blue componets of the filter
-
- EXAMPLE:
-
- TanFilter : RGBtype;
- Apal : RBGlist;
-
- TanFilter.red := 63;
- TanFilter.green := 30;
- TanFilter.blue := 13;
- fgetcolors(Apal); { grab the current palette }
- ChangeColors(Apal,TanFilter);
- fsetcolors(Apal); { change the palette to tan screen }
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ColorCycle(var colors:rgblist;start:byte;count:integer;fwd:boolean);
-
- Cycles a range of colors one step forward or backwards.
-
- COLORS: Palette to change;
- START: Starting color index;
- COUNT: Number of colors to rotate;
- FWD: Set to TRUE to cycle forward
-
- EXAMPLE:
-
- var
- Apal : RGBlist;
-
- fgetcolors(Apal);
- repeat
- ColorCycle(Apal,0,256,true); { Cycle the entire palette }
- fsetcolors(Apal); { using fsetcolors to set the palette }
- until crt.Keypressed; { until a key is pressed }
-
- ───────────────────────────────────────────────────────────────────────────
- function LoadColors(filename:string;var colors):integer;
-
- Load a color palette from disk.
-
- FILENAME: Palette dos file name;
- COLORS: Buffer to store the palette;
-
- Can read raw 768 byte .pal files or Ani pro .col files
-
- ───────────────────────────────────────────────────────────────────────────
- function SaveColors(filename:string;var colors;raw:boolean):integer;
-
- Save a color palette to disk.
-
- FILENAME: Palette dos file name;
- COLORS: Palette to save;
- RAW: Set to TRUE to save as a raw 768 byte file, or FALSE
- to save in an Animator Pro .COL file
- ───────────────────────────────────────────────────────────────────────────
- procedure Paint(x,y:integer;n:byte);
-
- Flood fills a region.
-
- X,Y: The location to start filling;
- N: The color to fill
-
- NOTE: This procedure does not use the a border algorthim. It fills
- the area with color (n) that has the occurances of the color at
- location (X,Y)
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CopyTo(x1,y1,x2,y2,x,y:integer;var from,too);
-
- Copies a region to another area.
-
- X1,Y1: Top-left coordinate of the source region;
- X2,Y2: Bottom-right coordinate of the source region;
- X,Y: Top-left coordinate of the destination region;
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- NOTE: Unpredictable results will happen if the source and destination page
- are the same and the region overlapps.
-
- ───────────────────────────────────────────────────────────────────────────
- function LoadVSP(fn:string;var buff):integer;
-
- Load a sprite file.
-
- FN: DOS file name of the .VSP file;
- BUFF: An array of pointer to hold the sprites
-
- NOTE: Buff MUST be a pointer, or an array of pointer. And they can NOT
- be preallocated. Does not check the array is smaller that the number
- of sprites in the file. Returns the number of sprites loaded.
-
- EXAMPLE:
-
- var
- asprite : pointer;
- sprites : array[0..19] of pointer;
- moresp : array[0..20] of pointer;
-
- { below are legal statements }
-
- loadvsp('onevsp.vsp',asprite);
- loadvsp('20vsps.vsp',sprites);
- loadvsp('onevsp.vsp',moresp[10]);
-
- ───────────────────────────────────────────────────────────────────────────
- function FileVSP(var fil:file;var buff;size:longint):integer;
-
- Loads sprites from an open file.
-
- FIL: Binary file that contains sprites;
- BUFF: An array of pointer to hold the sprites;
- SIZE: Size of the sprites in the area.
-
- NOTE: Does not close the file. Returns the number of sprites loaded.
- Be sure that SIZE corresponds to the exact size of the sprites to
- load.
-
- ───────────────────────────────────────────────────────────────────────────
- function AnalyzeScreen:byte;
-
- Returns the color number that is used the most on the active page.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure MemWrite(var source,dest;size:word;var off:longint);
-
- Copies data from SOURCE to DEST.
-
- SOURCE: Source buffer;
- DEST: Destination buffer;
- SIZE: Number of bytes to copy;
- OFF: Offset in DEST to start the copy
-
- NOTE: Upon returning OFF = OFF+SIZE
-
- ───────────────────────────────────────────────────────────────────────────
- procedure MemRead(var source,dest;size:word;var off:longint);
-
- Copies data from SOURCE to DEST.
-
- SOURCE: Source buffer;
- DEST: Destination buffer;
- SIZE: Number of bytes to copy;
- OFF: Offset in SOURCE to start the copy
-
- NOTE: Upon returning OFF = OFF+SIZE
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fwput(x1,y1:integer;var image);
-
- Displays a sprite on the active page. Forces even amount width moves.
-
- X1,Y1: Coordinate to place top-left of sprite.
- IMAGE: Sprite;
-
- ───────────────────────────────────────────────────────────────────────────
- procedure moveDW(var source,dest;size:word);
-
- Same as Turbo Pascal's move procedure. Uses 386 instructions.
-
- SOURCE: Source buffer;
- DEST: Destination buffer;
- SIZE: Size in bytes of memory to copy
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fputDW(x:word;var buff);
-
- Displays a sprite on the active page. Forces 386 instructions. Does
- not preform any clipping.
-
- X: Offset of the active page. E.G. = pt(x,y);
- BUFF: Sprite to display
-
- NOTE: This is the fastest sprite drawing routine. The width of the
- sprite must be divisible by 4.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure PcopyDW(var from,too);
-
- Same a fPcopy. Forces 386 instructions. Copies one page to another.
-
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fillDW(var dest;c:word;v:byte);
-
- Fills a memory region with the value V. Forces 386 instructions.
-
- DEST: The memory area to fill;
- C: Number of bytes to fill;
- V: Value to fill
-
- ───────────────────────────────────────────────────────────────────────────
- procedure clsDW(c:byte);
-
- Same as CLS. Clears the active page. Forces 386 instructions.
-
- C: The color to clear the active page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fhLine(x1,x2,y:integer;c:byte);
-
- Draws a horzontal line. Fast!
-
- X1,X2: Horzontal coordinates
- Y: Vertical coordinate
- C: Color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure DrawPoly(offx,offy:integer;poly:Tpoly;c:byte);
-
- Draws a outlined polygon.
-
- OFFX,OFFY: Start location of polygon
- POLY: Polygon structure
- C: Color
-
- EXAMPLE:
-
- var
- p : tPoly;
- begin
- p.init;
- p.addpoint(10,10);
- p.addpoint(-10,10);
- p.addpoint(-10,-10);
- p.addpoint(10,-10);
- p.addpoint(10,10);
- DrawPoly(160,100,p,15);
- end;
-
- Draws a box of color 15
-
- ───────────────────────────────────────────────────────────────────────────
- procedure FillPoly(offx,offy:integer;poly:Tpoly;c:byte);
-
- Draws a filled polygon. Not the fastest. "Its my first attempt ;)"
-
- OFFX,OFFY: Start location of polygon
- POLY: Polygon structure
- C: Color
-
- EXAMPLE:
-
- var
- p : tPoly;
- begin
- p.init;
- p.addpoint(10,10);
- p.addpoint(-10,10);
- p.addpoint(-10,-10);
- p.addpoint(10,-10);
- p.addpoint(10,10);
- FillPoly(160,100,p,15);
- end;
-
- Draws a filled box of color 15
-
- ───────────────────────────────────────────────────────────────────────────